package org.core.controller;


import io.github.yezhihao.netmc.session.SessionManager;
import io.github.yezhihao.protostar.SchemaManager;
import io.github.yezhihao.protostar.util.Explain;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.protocol.basics.JTMessage;
import org.protocol.codec.DataFrameMessageDecoder;
import org.protocol.codec.JTMessageDecoder;
import org.protocol.codec.MultiPacketDecoder;
import org.protocol.t808.T0702;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("test/")
@Slf4j
public class TestController {

    private final SessionManager sessionManager;

    private final JTMessageDecoder decoder;



    public TestController(SessionManager sessionManager, SchemaManager schemaManager) {
        this.sessionManager = sessionManager;
        this.decoder = new MultiPacketDecoder(schemaManager);
    }


    @Operation(summary = "808协议分析工具")
    @RequestMapping(value = "message/explain", method = {RequestMethod.POST, RequestMethod.GET})
    public String decode(@Parameter(description = "16进制报文") @RequestParam String hex) {
        JTMessage decode = decoder.decode(Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump(hex)));
        log.info("解析的消息体{}",decode);
        return decode.toString();
    }
}
